
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

package com.hlkj.pay.util;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.hlkj.framework.common.util.json.JsonUtils;
import com.hlkj.pay.vo.common.req.MessageSendParamsReq;
import jodd.util.StringPool;

import java.util.Map;

/**
 * @author monk@techsun.com
 * @date 2023/04/25 11:29
 */
public class TemplateVariableUtils {

   
    

    /**
     *
     * @param content
     * @param templateParameter
     * @return
     */
    public static String messageText(String content, String templateParameter) {
        if (StringUtils.isBlank(templateParameter)) {
            return content;
        }
        MessageSendParamsReq messageSendParamsReq = JsonUtils.parseObject(templateParameter,
                MessageSendParamsReq.class);
        if (messageSendParamsReq==null) {
            return content;
        }
        Map<String, Object> stringObjectMap = BeanUtil.beanToMap(messageSendParamsReq);
        try {
            for (String templateKey : stringObjectMap.keySet()) {
                if (content.contains(templateKey)) {
                    content = content.replace(StringPool.DOLLAR+StringPool.LEFT_BRACE + templateKey + StringPool.RIGHT_BRACE, stringObjectMap.get(templateKey).toString());
                }
            }
        }
        catch (Exception e) {
        }
        return content;
    }

    

    /**
     *
     * @param messageSendParamsReq
     * @return
     */
    public static String sequenceMessageData(MessageSendParamsReq messageSendParamsReq) {
        MessageSendParamsReq messageSendParams = new MessageSendParamsReq();
        messageSendParams.setCouponName(messageSendParamsReq.getCouponName());
        messageSendParams.setCouponNo(messageSendParamsReq.getCouponNo());
        messageSendParams.setCustomerMemberSigned(messageSendParamsReq.getCustomerMemberSigned());
        messageSendParams.setCustomerName(messageSendParamsReq.getCustomerName());
        messageSendParams.setCustomerNo(messageSendParamsReq.getCustomerNo());
        messageSendParams.setCouponEffectTime(messageSendParamsReq.getCouponEffectTime());
        messageSendParams.setCouponInvalidTime(messageSendParamsReq.getCouponInvalidTime());
        messageSendParams.setCustomerLeave(messageSendParamsReq.getCustomerLeave());
        messageSendParams.setPointChange(messageSendParamsReq.getPointChange());
        messageSendParams.setPointEffectTime(messageSendParamsReq.getPointEffectTime());
        messageSendParams.setPointInvalidTime(messageSendParamsReq.getPointInvalidTime());
        messageSendParams.setPointAvailable(messageSendParamsReq.getPointAvailable());
        messageSendParams.setBoundPhone(messageSendParamsReq.getBoundPhone());
        messageSendParams.setBusinessCode(messageSendParamsReq.getBusinessCode());
        messageSendParams.setSendType(messageSendParamsReq.getSendType());
        messageSendParams.setSendTime(messageSendParamsReq.getSendTime());
        messageSendParams.setCode(messageSendParamsReq.getCode());
        messageSendParams.setTemplateCode(messageSendParamsReq.getTemplateCode());
        messageSendParams.setSn(messageSendParamsReq.getSn());
        messageSendParams.setAccount(messageSendParamsReq.getAccount());
        return JsonUtils.toJsonString(messageSendParams);
    }
   
}
